package com.firmboy.mysql;

import com.firmboy.mysql.db.DBHelper;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * mysql的锁的实验
 *
 * @author firmboy
 * @create 2018-05-05 下午12:09
 **/
public class MysqlLock {


    @Test
    public void ATest() throws SQLException {
        Connection conn = DBHelper.getConn();

        conn.setAutoCommit(false);

        PreparedStatement ps = conn.prepareStatement("insert into account VALUES (1,'tom','1000')");

        ps.execute();


        while (true){}


    }


    @Test
    public void BTest() throws SQLException {

        Connection conn = DBHelper.getConn();

        conn.setAutoCommit(false);

        try{
            PreparedStatement ps = conn.prepareStatement("INSERT INTO account VALUES (2,'joy','2000')");

            ps.execute();

        }catch(Exception e){
            e.printStackTrace();
        }

        conn.commit();


    }








}
